package com.gjy.datetime.time;

import com.gjy.util.DatetimeUtil;
import org.junit.jupiter.api.Test;

import java.time.Clock;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-03-31 14:06:43
 */
public class InstantTest {

    @Test
    public void test7() {
        ZonedDateTime zonedDateTime = Instant.now().atZone(ZoneId.systemDefault());
        System.out.println(zonedDateTime);
    }

    @Test
    public void test6() {
        Clock clock = Clock.systemDefaultZone();
        System.out.println("clock = " + clock);

        long millis = clock.millis();
        System.out.println("DatetimeUtil.parse(millis) = " + DatetimeUtil.parse(millis));
    }

    @Test
    public void test5() {
        Instant instant = Clock.systemDefaultZone().instant();
        System.out.println("instant = " + instant);
    }

    @Test
    public void test4() {
        Instant plus = Instant.now().plus(8, ChronoUnit.HOURS);
        System.out.println("plus = " + plus);
    }

    @Test
    public void test3() {
//        Instant now = Instant.now(Clock.system(ZoneId.systemDefault()));
        Instant now = Instant.now(Clock.system(ZoneId.of("America/Puerto_Rico")));
        System.out.println("now = " + now);
    }

    @Test
    public void test2() {
        Instant now = Instant.now();
        Instant n2 = Instant.now(Clock.systemUTC());
        System.out.println("now = " + now);
        System.out.println("n2 = " + n2);
    }

    @Test
    public void test1() {
        Instant instant = Instant.ofEpochSecond(System.currentTimeMillis() / 1000);
        instant.atZone(ZoneId.systemDefault());

        System.out.println("instant = " + instant);
    }
}
